module.exports = function ($scope, $resource, getDate, toaster) {

    var today = getDate(new Date());
    $scope.total = {}
    $scope.date = {
        'lable': today,
        'opened': false
    };
    $scope.date1 = {
        'lable': today,
        'opened': false
    };

    $scope.search = function () {
        $scope.total.pay_price = 0;
        $scope.total.num = 0;
        $scope.total.used = 0;
        $scope.total.back = 0;
        $scope.total.subsidy_price = 0;
        $scope.total.redpacket_price = 0;
        var para = {
            'name': $scope.name,
            'start_time': getDate($scope.date.lable),
            'end_time': getDate($scope.date1.lable)
        }

        $resource('/api/as/mc/shoporder/getOrderCountList', {}, {}).save(para, function (res) {
            if (res.errcode === 0) {
                $scope.countList = res.data;
                res.data.forEach(element => {
                    $scope.total.pay_price += element.pay_price || 0;
                    $scope.total.num += element.num;
                    $scope.total.used += element.used;
                    $scope.total.back += element.back;
                    $scope.total.subsidy_price += element.subsidy_price || 0;
                    $scope.total.redpacket_price += element.redpacket_price || 0;
                });

            } else {
                toaster.error({ title: '', body: '统计订单失败'});
            }
        });
    }
    $scope.search();
    
    //打开日历空间,选择时间
    $scope.dateOpen = function ($event, item) {
        $event.preventDefault();
        $event.stopPropagation();
        item.opened = true;
    };

};